// --------------------------------------------------------------------------------------------------------------------
// <copyright file="PicknPlaceKukaRobotiqGrip.cs" company="Microsoft Corporation">
// The MIT License (MIT)
// 
// Copyright (c) 2014, Microsoft Corporation
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Microsoft.Robotics.Hardware
{
    using System;
    using Microsoft.Robotics.Manipulation.PicknPlace;
    using Microsoft.Robotics.Numerics;

    /// <summary>
    /// Pick and place grips for and arm / hand combination using KUKA LBR arm and Robotiq hand
    /// </summary>
    public class PicknPlaceKukaRobotiqGrip : PicknPlaceGenericArmFingerGripper
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="PicknPlaceKukaRobotiqGrip" /> class
        /// </summary>
        public PicknPlaceKukaRobotiqGrip()
        {
            this.ArmTCPPalmOffsetInM = 0.020;
            this.PalmPlaneDefault = Vector3.Normalize(new Vector3(0, 0, 1));
            this.PalmPlaneGripAxis = Vector3.Normalize(new Vector3(25, 25, 0));
            this.SimpleGripperBoxModel = new Vector3(0.105, 0.04, 0.180);
            this.PreGripOffsetAlongGripNormalInM = 0.128;
            this.MinArmReachInMForTopDown = 0.52;
            this.MinArmReachInM = 0.52;
            this.MaxArmReachInMForTopDown = 0.96;
            this.MaxArmReachInM = 0.94;
            this.MaxArmReachXYInM = 0.90;
            this.MaxArmReachXYInMForTopDown = 0.78;
            this.MaxFullyExtendXYForTopDown = 0.761;
            this.MaxFullyExtendElevationForTopDown = 0.3;
            this.MaxYclearance = -0.41;
            this.MinZClearanceOverTable = 0.01;
            this.MinArmGripperOrientThreshold = -0.5;
            this.MaxFullyRetractedElevationWrap = 0.2;
            this.MinReachXYForWrap = 0.54;
            this.GripperRatePerM = 322.6;
            this.GripperOpenPercentOffset = 50.0;
            this.ArmName = "Kuka";

            double cosAng = Vector3.Dot(this.PalmPlaneDefault, this.PalmPlaneGripAxis);
            if (cosAng > MathConstants.ErrorEpsilon)
            {
                throw new Exception("Hand grip axis must be orthogonal to palm normal");
            }
        }
    }
}
